package com.anti.modular.sys.org.controller;
import com.anti.commom.annotation.DataScope;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.pojo.BaseParam;
import com.anti.jdbc.support.page.PageParam;
import com.anti.commom.annotation.BusinessLog;
import com.anti.modular.sys.org.param.SysOrgParam;
import com.anti.modular.sys.org.service.SysOrgService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统组织机构控制器
 */
@RestController
@RequestMapping("sysOrg")
public class SysOrgController {

    @Resource
    private SysOrgService sysOrgService;

    /**
     * 查询系统机构
     */
    @GetMapping("page")
    @DataScope
    @BusinessLog(title = "系统机构_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam,SysOrgParam sysOrgParam) {
        return Result.data(sysOrgService.page(pageParam,sysOrgParam));
    }

    /**
     * 系统组织机构列表
     */
    @DataScope
    @GetMapping("list")
    @BusinessLog(title = "系统组织机构_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result list(SysOrgParam sysOrgParam) {
        return Result.data(sysOrgService.list(sysOrgParam));
    }

    /**
     * 添加系统组织机构
     */
    @Permission
    @DataScope
    @PostMapping("add")
    @BusinessLog(title = "系统组织机构_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysOrgParam.add.class) SysOrgParam sysOrgParam) {
        sysOrgService.add(sysOrgParam);
        return Result.success("增加成功！");
    }

    /**
     * 删除系统组织机构
     */
    @Permission
    @DataScope
    @PostMapping("delete")
    @BusinessLog(title = "系统组织机构_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(SysOrgParam.delete.class) SysOrgParam sysOrgParam) {
        sysOrgService.delete(sysOrgParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑系统组织机构
     */
    @Permission
    @DataScope
    @PostMapping("edit")
    @BusinessLog(title = "系统组织机构_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(BaseParam.edit.class) SysOrgParam sysOrgParam) {
        sysOrgService.edit(sysOrgParam);
        return Result.success("修改成功");
    }

    /**
     * 查看系统组织机构
     */
    @Permission
    @GetMapping("detail")
    @BusinessLog(title = "系统组织机构_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result detail(@Validated(BaseParam.detail.class) SysOrgParam sysOrgParam) {
        return Result.data(sysOrgService.detail(sysOrgParam));
    }

    /**
     * 获取组织机构树
     */
    @Permission
    @DataScope
    @GetMapping("tree")
    @BusinessLog(title = "系统组织机构_树", opType = LogAnnotionOpTypeEnum.TREE)
    public Result tree(SysOrgParam sysOrgParam) {
        return Result.data(sysOrgService.tree(sysOrgParam));
    }
}
